package com.opo5.logisticsmanagement.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.opo5.logisticsmanagement.common.R;
import com.opo5.logisticsmanagement.dao.MessageDao;
import com.opo5.logisticsmanagement.domain.Message;
import com.opo5.logisticsmanagement.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author lixin
* @description 针对表【tbs_message】的数据库操作Service实现
* @createDate 2022-07-10 08:55:41
*/
@Service
public class MessageServiceImpl extends ServiceImpl<MessageDao, Message>
    implements MessageService {


    @Autowired
    private MessageDao messageDao;

    @Override
    public R getMessageByCondition(String title) {
        QueryWrapper<Message> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(title!=null,"title",title);
        queryWrapper.eq("status",0);
        List<Message> messages = messageDao.selectList(queryWrapper);
        return R.success(messages);
    }

    @Override
    public R editMessage(Integer id) {
        Message message = new Message();
        message.setStatus("1");
        message.setId(id);
        Integer flag = messageDao.updateById(message);

        if (flag == 1){
            return R.success(null);
        }
        return R.error("阅读成功");
    }

    @Override
    public R editAllMessage() {
        UpdateWrapper<Message> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("status","0");
        updateWrapper.set("status","1");
        messageDao.update(null,updateWrapper);
        return R.success(null);
    }
}




